package com.zhdl.modules.demo.DCHTProcess;

import com.zhdl.common.ytools.callback.CommonCallback;
import com.zhdl.modules.process.BaseProcess;
import com.zhdl.modules.process.dto.ProcessBean;
import com.zhdl.modules.process.task.CustomizeTask;
import com.zhdl.modules.process.verify.DelayTimeVerify;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class TransportTHQProcess extends BaseProcess {
    @Resource
    MainProcessInit mainProcessInit;
    CommonCallback<String> transportComplete;
    @Override
    public void initHardware() {
        processBeanList = mainProcessInit.initTransportTHQ();
        statusHolder. initComplete = true;
        statusHolder.setAuto(true);
    }

    @Override
    public void startProcess(Integer process) {
        String data;
        if (process == processBeanList.size() - 1) {
            data = "-2";
            if (transportComplete!=null) {
                transportComplete.statusCallback("ok");
            }
        } else {
            data = String.valueOf(process + 1);
        }
        if (process == 0 && statusHolder.yield > 0) {
            log.info(getClass().getName() + "本次流程数据{}", processBeanList);
            processBeanList = mainProcessInit.initTransportTHQ();
        }
        ProcessBean processByStep = processBeanList.get(process);
        if (processByStep != null) {
            processByStep.getProcessDo().doSomeThing();
            if (processByStep.getProcessVerify() == null) {
                processByStep.setProcessVerify(new DelayTimeVerify(2000));
            }
            processByStep.setRunStatus(1);
            dynamicTask.startTask(new CustomizeTask(processByStep,statusHolder), process == 13 ? 10 : 100);
        }
    }

    @Override
    public void initProcessList() {

    }

    public void test(Integer process) {
        statusHolder.process = process;
        statusHolder.isRunning = false;
        ProcessBean processByStep = processBeanList.get(process);
        if (processByStep != null) {
            log.info("测试流程进行至" + processByStep.getDesc() + "停止");
        }
    }
    public void startTransport(CommonCallback<String> callback){
        statusHolder.start();
        transportComplete = callback;
    }
}
